package com.diancan.web.controller.dc;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.diancan.common.annotation.Log;
import com.diancan.common.enums.BusinessType;
import com.diancan.dc.domain.DcFoodInfo;
import com.diancan.dc.service.IDcFoodInfoService;
import com.diancan.common.core.controller.BaseController;
import com.diancan.common.core.domain.AjaxResult;
import com.diancan.common.utils.poi.ExcelUtil;
import com.diancan.common.core.page.TableDataInfo;

/**
 * 美食管理Controller
 *
 * @author dc
 * @date 2021-12-27
 */
@Controller
@RequestMapping("/dc/fodoInfo")
public class DcFoodInfoController extends BaseController {
    private String prefix = "dc/fodoInfo";

    @Autowired
    private IDcFoodInfoService dcFoodInfoService;

    @RequiresPermissions("dc:fodoInfo:view")
    @GetMapping()
    public String fodoInfo() {
        return prefix + "/fodoInfo";
    }

    @GetMapping("/customView")
    public String customView() {
        return prefix + "/customView";
    }

    /**
     * 查询美食管理列表
     */
    @RequiresPermissions("dc:fodoInfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DcFoodInfo dcFoodInfo) {
        startPage();
        List<DcFoodInfo> list = dcFoodInfoService.selectDcFoodInfoList(dcFoodInfo);
        return getDataTable(list);
    }

    /**
     * 导出美食管理列表
     */
    @RequiresPermissions("dc:fodoInfo:export")
    @Log(title = "美食管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DcFoodInfo dcFoodInfo) {
        List<DcFoodInfo> list = dcFoodInfoService.selectDcFoodInfoList(dcFoodInfo);
        ExcelUtil<DcFoodInfo> util = new ExcelUtil<DcFoodInfo>(DcFoodInfo.class);
        return util.exportExcel(list, "美食管理数据");
    }

    /**
     * 新增美食管理
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存美食管理
     */
    @RequiresPermissions("dc:fodoInfo:add")
    @Log(title = "美食管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DcFoodInfo dcFoodInfo) {
        return toAjax(dcFoodInfoService.insertDcFoodInfo(dcFoodInfo));
    }

    /**
     * 修改美食管理
     */
    @RequiresPermissions("dc:fodoInfo:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        DcFoodInfo dcFoodInfo = dcFoodInfoService.selectDcFoodInfoById(id);
        mmap.put("dcFoodInfo", dcFoodInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存美食管理
     */
    @RequiresPermissions("dc:fodoInfo:edit")
    @Log(title = "美食管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DcFoodInfo dcFoodInfo) {
        return toAjax(dcFoodInfoService.updateDcFoodInfo(dcFoodInfo));
    }

    /**
     * 删除美食管理
     */
    @RequiresPermissions("dc:fodoInfo:remove")
    @Log(title = "美食管理", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(dcFoodInfoService.deleteDcFoodInfoByIds(ids));
    }
}
